package edu.colorado.csci5548.gps_messenger;

import java.util.*;

public class LocationList 
{
	private List<Location> _locationList;
	
	LocationList()
	{
		_locationList = new ArrayList<Location>(100);
	}
	
	LocationList(LocationList locationList)
	{
		this();
		Iterator<Location> locationIterator = locationList.iterator();
		while(locationIterator.hasNext())
		{
			Location l = (Location) locationIterator.next();
			_locationList.add(l);
		}
	}	
	
	public Iterator<Location> iterator()
	{
	    return _locationList.iterator();
	}

	public int size()
	{
		return _locationList.size();
	}
	
	public void add(Location location)
	{
		_locationList.add(location);
	}
	
	public void remove(Location location)
	{
		Iterator<Location> locationIterator = _locationList.iterator();
		while(locationIterator.hasNext())
		{
			Location l = (Location) locationIterator.next();
			if (l.equals(location))
			{
				_locationList.remove(l);
				break;
			}
		}
	}	
	
	public boolean contains(Location location)
	{
		Iterator<Location> locationIterator = _locationList.iterator();
		while(locationIterator.hasNext())
		{
			Location l = (Location) locationIterator.next();
			if (l.equals(location))
			{
				return true;
			}
		}
		return false;
	}
	
	public String toString()
	{
		return _locationList.toString();
	}
}
